#ifndef H_SCOPE_GUARD

#define H_SCOPE_GUARD

namespace	Platform
{

	namespace	Common
	{

		template<typename TElementType>
		class	TScopeGuard
		{
		public:
			TScopeGuard(TElementType *guard) : m_Guard(guard)
			{
				if (CHECK_POINT_NO_NULL(m_Guard))
				{
					m_Guard->Lock(WAIT_INFINITE);
				}
			}
			~TScopeGuard()
			{
				if (CHECK_POINT_NO_NULL(m_Guard))
				{
					m_Guard->Unlock();
					m_Guard = NULL_ADDRESS;
				}
			}
		private:
			TElementType							*m_Guard;
		};

	}

}

#endif
